package com.cyandpos.pad.cateringformat.orderinfo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.pay.adapter.BaseViewHolder;
import com.cyandpos.pad.posdata.Order;

import java.util.ArrayList;
import java.util.List;

public class OrderInfoAdapter  extends BaseAdapter{

    private Context context;
    private List<Order> skfs = new ArrayList<>();
    private int clickTemp = -1;//标识被选择的item
    private int[] clicked;
    private boolean mFlag;
    private boolean isMore=true;
    public OrderInfoAdapter(Context mContext, List<Order> mSkfs) {
        super();
        this.context = mContext;
        this.skfs = mSkfs;
    }

    @Override
    public int getCount() {
        return skfs.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate
                    (R.layout.item_orderinfo_order, parent, false);
        }

        LinearLayout lin_table_item = BaseViewHolder.get(convertView, R.id.lin_orderfood_item);
        TextView tv_info_inx = BaseViewHolder.get(convertView, R.id.tv_orderfood_info_inx);
        TextView tv__order = BaseViewHolder.get(convertView, R.id.tv_orderfood_order);
        TextView tv__tableid = BaseViewHolder.get(convertView, R.id.tv_orderfood_info_tableid);
        TextView tv_booktime = BaseViewHolder.get(convertView, R.id.tv_orderfood_info_booktime);
        TextView tv__status = BaseViewHolder.get(convertView, R.id.tv_orderfood_info_status);
        tv_info_inx.setText((position+1)+"");
        tv__order.setText(skfs.get(position).getOrderNo());
        tv__tableid.setText(skfs.get(position).getTableId()+""); //桌号没有
        tv_booktime.setText(skfs.get(position).getOrderBeginTime());
        tv__status.setText(getStatus(skfs.get(position).getStatus()));

        // tv.setTextColor(context.getResources().getColor(R.color.main_title_text));

        if(clickTemp==position){    //根据点击的Item当前状态设置背景
            if(mFlag){
                // tv.setTextColor(context.getResources().getColor(R.color.white) );
                lin_table_item.setBackgroundResource(R.drawable.pay_item_bg_true);
            }else if(!mFlag){
                // tv.setTextColor(context.getResources().getColor(R.color.main_title_text) );
                  lin_table_item.setBackgroundResource(R.drawable.pay_item_bg_false);
            }
        }else{
            // tv.setTextColor(context.getResources().getColor(R.color.main_title_text) );
           //  lin_table_item.setBackgroundResource(R.drawable.pay_item_bg_false);
        }
        return convertView;
    }
    public void setSelectPos(int position,boolean flag) {
        clickTemp = position;
        mFlag = flag;
        notifyDataSetChanged();
    }

    public String getStatus(String status){
        String  str_status="未知";
 //0 是点菜    2 预结   3 是部分付款  1 是完成
        if (status.equals("1")){
            str_status="已付款";
        }else if (status.equals("0")){
            str_status="已点菜";
        }else if (status.equals("2")){
            str_status="未付款";
        }else if (status.equals("3")){
            str_status="部分付款";
        }
     return str_status;

    }

}
